define(function () {
    return function (pane) {
        /**
         * 导航
         */
        {
            pane.html(utils.getHtml('default_table'));

            utils.addFilterGroupbtn(pane, {
                text: '全部状态',
                name: 'showRefundStatus',
                filters: [
                    {text: '维权成功', value: '维权成功'},
                    {text: '等待处理', value: '等待处理'},
                    {text: '维权失败', value: '维权失败'},
                    {text: '维权创建', value: '维权创建'}
                ]
            });

            utils.addFilterGroupbtn(pane, {
                text: '全部',
                name: 'status',
                filters: dicts.order_status
            });

            utils.addFilterGroupbtn(pane, {
                text: '全部',
                name: 'is_back',
                filters: [
                    {value: "0", text: "未退款"},
                    {value: "1", text: "已退款"}
                ]
            });
        }

        /**
         * 统计
         */
        {
            var analyse = function () {
                // adminApi('refunds_analyse').then(function (rows) {
                //     console.log(rows);
                // });
            }
            analyse();
        }

        //初始化工具
        utils.addTools(pane, [
            {className: 'refresh-btn', icon: 'fa-refresh', text: '刷新'}
        ]);
        $(pane).on('click', '.refresh-btn', function () {
            if (table) {
                table.api().draw();
                analyse();
            }
        });

        //初始化表格
        var table = utils.dataTable(pane, {
            columns_arrays: [
                ["id", "#"],
                ["partner_id", "合伙人", false, function (i, t, row) {
                    var user = row.partner;
                    if (!user) {
                        return '';
                    }
                    return (user.image ? '<img src="' + user.image + '?imageView2/1/w/150/h/150/q/75"> ' : '') + '<div>' + (user.nickname || user.tel) + '</div><div>「ID:' + (user.id) + '」</div>';
                }, 'filterable'],
                ["agency_id", "代理", false, function (i, t, row) {
                    var user = row.agency;
                    if (!user) {
                        return '';
                    }
                    return (user.image ? '<img src="' + user.image + '?imageView2/1/w/150/h/150/q/75"> ' : '') + '<div>' + (user.nickname || user.tel) + '</div><div>「ID:' + (user.id) + '」</div>';
                }, 'filterable'],
                ["user_id", "用户", false, function (i, t, row) {
                    var user = row.user;
                    if (!user) {
                        return '';
                    }
                    return (user.image ? '<img src="' + user.image + '?imageView2/1/w/150/h/150/q/75"> ' : '') + '<div>' + (user.nickname || user.tel) + '</div><div>「ID:' + (user.id) + '」</div>' + '<div>订单数: ' + user.order_count + '/' + user.finish_count + '/' + user.sham_count + '&nbsp;&nbsp;金额: ' + user.amount + '/' + user.frozen + '</div>';
                }, 'filterable'],
                ["tbAuctionId", "商品名", false, function (i, t, row) {
                    return '<div style="max-width: 160px;">' + (row.tbAuctionTitle || '') + '</div>';
                }, 'filterable'],
                ["tbSellerShopTitle", "店铺", false, function (i, t, row) {
                    return '<div style="max-width: 160px;">' + (row.tbSellerShopTitle || '') + '</div>';
                }, 'filterable'],
                ["showRefundStatus", "状态", false],

                ["id", "退款状态", false, function (i, t, row) {
                    return '<div style="min-width: 150px;"><div>' + row.tbTradeParentId + '</div>' +
                        '<div>' + row.tbTradeId + '</div>' +
                        '<div>退款金额:<span class="badge" style="background-color: #00a65a!important; cursor: pointer;">￥' + (row.refundFee || 0) + '</div>' +
                        '<div>返还金额:<span class="badge" style="background-color: #f39c12!important; cursor: pointer;">￥' + (row.showReturnFee || 0) + '</div>' +
                        '<div>' + row.showRefundReason + '</div></div>';
                }],

                ["is_back", "是否退回", false, utils.dictRender('boolean')],
                ["status", "状态", false, utils.dictRender('order_status')],

                ["refundCreateTime", "创建时间", true, utils.dateTimeRender()],
                ["refundFinishTime", "完成时间", true, utils.dateTimeRender()],
                ["earningTime", "结算时间", true, utils.dateTimeRender()],
                ["created_at", "创建时间", false, utils.dateTimeRender()]
            ],
            sorting: [[0, 'desc']],
            fnServerData: function (paramData) {
                return adminApi('refunds_browse', paramData);
            }
        });
    }
});